package ru.neoflex.datatable;

import java.util.HashMap;
import java.util.Map;

import ru.neoflex.dataobject.DataObjectDescriptor;
import ru.neoflex.dataobject.DataObjectProperty;

public class DataObjectUtils {
	public static Map<String, Object> generateEmptyMapByDescriptor(DataObjectDescriptor descriptor) {
		Map<String, Object> map = new HashMap<String, Object>();
		for (DataObjectProperty property : descriptor.getProperties()) {
			map.put(property.getName(), null);
		}
		return map;
	}
	
	public static Map<String, Object> generateMapByDescriptor(DataObjectDescriptor descriptor, Object... values) {
		Map<String, Object> map = new HashMap<String, Object>();
		for (int i = 0; i < descriptor.getProperties().size(); i++) {
			DataObjectProperty property = descriptor.getProperties().get(i);
			String name = property.getName();
			Object value = null;
			if (i < values.length) {
				value = values[i];
			}
			map.put(name, value);
		}		
		return map;
	}
}
